package com.dhht.annotationlibrary;
import android.app.Activity;
public class MyAnnotation {

    public static void injectView(Activity activity) {
        CatViewInject proxyActivity = (CatViewInject ) findProxyActivity(activity);
        if (proxyActivity == null) {
            return;
        }
        // 执行 新类的 inject() 操作
        proxyActivity.inject(activity, activity);
    }


    private static final String SUFFIX = "$$CatViewInject";
    private static Object findProxyActivity(Activity  activity) {
        try {
            Class clazz = activity.getClass();
            //  MainActivity$$CatViewInject
            // Class.forName 要求JVM查找并加载指定的类
            Class injectorClazz = Class.forName( clazz.getName() + SUFFIX );
            // 返回一个新类对象
            return  injectorClazz.newInstance();
        } catch (Exception e) {
            return null;
        }
    }
}
